/** @defgroup SPI_FLASH Cargo SPI_FLASH
 * @{
 */
/*
 * Application\Inc\spi_flash.h
 *
 * Cargo spi_flash control
 *
 * Author: Chao-Chi Kuo <chaochi_kuo@systech.com.tw>
 * Copyright (c) 2010 SYSTEMS & TECHNOLOGY CORP. <http://www.systech.com.tw/>
 * All rights reserved.
 *
 * Modifications:
 * 2009/11/18 Chao-Chi Kuo	first implemetation
 *
 * $Id: spi_flash.h 196 2010-08-05 01:54:48Z chaochi_kuo $
 */

#ifndef __SPI_FLASH_H_
#define __SPI_FLASH_H_

#ifdef  __cplusplus
extern "C" {
#endif		/* __cplusplus */

/** @name SPI ERROR CODE DEFINE
 * @{
 */
#define SPI_FLASH_OK		0	///< Success
#define SPI_FLASH_ERR		1	///< Error:flash busy
/** @} */
extern void SPI_Flash_Power_On(void);
extern void SPI_Flash_Power_Off(void);

extern unsigned long SPI_Flash_ReadID(void);
extern unsigned char SPI_Flash_Page_Erase(unsigned long addr);
extern unsigned char SPI_Flash_SubSector_Erase(unsigned long addr);
extern unsigned char SPI_Flash_Sector_Erase(unsigned long addr);
extern unsigned char SPI_Flash_Bulk_Erase(void);
/*
extern unsigned char SPI_Flash_Read(unsigned long addr,
									unsigned char *buf,
									unsigned short count);
*/
/*
extern unsigned char SPI_Flash_Write(	unsigned long addr,
										unsigned char *buf,
										unsigned short count);
*/
extern unsigned char SPI_Flash_Fast_Write(	unsigned long addr,
											unsigned char *buf,
											unsigned short count);
extern unsigned char SPI_Flash_Wait_Ready(void);
extern unsigned char SPI_Flash_Init(unsigned long id);
extern void SPI_Flash_Hook(void);
extern void SPI1_IRQ_CALLBACK(void);

unsigned char SPI_FLASH_GET_DATA(void);
void SPI_FLASH_SEND_DATA(unsigned char indata);
void SPI_FLASH_WaitForWriteEnd(void);
//void SPI_FLASH_BufferRead(unsigned char *pBuffer, unsigned long ReadAddr, unsigned short NumByteToRead);
void SPI_Flash_Read(unsigned long ReadAddr, unsigned char *pBuffer, unsigned short NumByteToRead);
//void SPI_FLASH_BufferWrite(unsigned char* pBuffer, unsigned long WriteAddr, unsigned short NumByteToWrite);
void SPI_Flash_Write(unsigned long WriteAddr, unsigned char* pBuffer, unsigned short NumByteToWrite);
void SPI_FLASH_PageWrite(unsigned char* pBuffer, unsigned long WriteAddr, unsigned short NumByteToWrite);
void SPI_FLASH_DisadbleProtection(void);
void SPI_FLASH_PageErase(unsigned long PageAddr);

#ifdef __cplusplus
}
#endif	/* __cplusplus */
#endif	/* __SPI_FLASH_H_ */
/** @} */